package ac.il.technion.cs236635.project.core;

import java.util.HashMap;
import java.util.Map;

import ac.il.technion.cs236635.project.core.Dispatcher;
import ac.il.technion.cs236635.project.core.generated.*;

/* TODO:
 * 1) Distribution of arriving tasks is Poisson(lambda * N), N = # of servers
 * 2) Two possible distributions for task lengths:
 *   * Bounded-Pareto(L, H, alpha), L - minimal task length,
 *       H - maximal task length, alpha - exponent of power-law
 *   * XXX: ???
 * 3) Statistics for:
 *   * HP:
 *     - Wait time
 *     - Finished or aborted
 *   * LP:
 *     - Wait time
 *     - Finished or aborted
 *     - Number of preemptions (if was executed)
 *   * Queues:
 *     - Average queue lengths
 *   * Total:
 *     - Rate of LP finished
 *     - Rate of HP finished
 *     - Average wait time
 *     - Average queue length
 *     - Performance improvement
 * 4) Consider whether we want to limit the HP queue.
 * 5) Consider whether we want to implement drop treshold to LP jobs.
 */
public class Producer {
	
	private Map<Integer, ServerJob> jMap = new  HashMap<Integer, ServerJob>();
	private Map<Integer, ServerPair> jServersMap = new  HashMap<Integer, ServerPair>();
	
	public static int getPoisson(double lambda) {
		double L = Math.exp(-lambda);
		double p = 1.0;
		int k = 0;

		do {
			k++;
			p *= Math.random();
		} while (p > L);

		return k - 1;
	}

	public static void main(String[] args) {
        Dispatcher d = (Dispatcher) new DispatcherService().getDispatcherPort();
        
        
        while(true){
        	ServerPair sp = d.acquireServer();
        	if (sp == null)continue;
        	
        }
    }
}